# -*- coding:utf-8 -*-
from functools import wraps

__author__ = "Jim"

"""
Create by Jim on2019/01/03
"""
from . import user
from flask import render_template, session, g


def user_info(func):
    @wraps(func)
    def wrapper(*args, **kwargs):
        user_id = session.get("user_id")
        if not user_id:
            return render_template("news/index.html")
        from app.models import User
        user = User.query.get(user_id)
        g.user = user
        return func(*args, **kwargs)

    return wrapper


@user.route('/')
@user_info
def index():
    return render_template("news/index.html", user=g.user)


@user.route('/pwd')
@user_info
def pwd():
    return render_template('news/user_pass_info.html')


@user.route('/info')
@user_info
def info():
    return render_template('news/user_info_info.html')


@user.route('/collection')
@user_info
def collection():
    return render_template('news/user_collection.html')


@user.route('/follow')
@user_info
def follow():
    return render_template('news/user_follow.html')


@user.route('/list')
@user_info
def list():
    return render_template('news/user_news_list.html')


@user.route('/pic_inco')
@user_info
def pic_inco():
    return render_template('news/user_pic_info.html')
